import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from "@/views/homes/index.vue"
import Search from "@/views/homes/search_Ranking.vue"
import Layout from "@/layout/index.vue"
import store from '@/store'

Vue.use(VueRouter)
export const routes1 = [
  {//默认路径
    path: "/",
    name: '/',
    redirect: "/home",
    hidden: true,
  },
  {//首页
    path: '/home',
    name: 'myhome',
    component: Layout,
    hidden: false,
    meta: {
      title: "七鲜",
      icon: "wap-home-o"
    },
    redirect: "/home/home",
    children: [
      {
        path: "/home/home",
        name: 'home',
        component: Home,
        meta: {
          title: "七鲜",
          icon: "wap-home-o"
        }
      },
      {
        path: "/home/search",
        name: 'search',
        component: Search,
        meta: {
          title: "搜索",
        }
      },
    ]
  },
  {//分类
    path: '/classifys',
    name: 'myclassifys',
    component: Layout,
    hidden: false,
    meta: {
      title: "分类",
      icon: "apps-o"
    },
    redirect: "/classifys/classifys",
    children: [
      {
        path: "/classifys/classifys",
        name: 'classifys',
        component: () => import("@/views/classifys/index.vue"),
        meta: {
          title: "分类",
          icon: "apps-o"
        }
      }
    ]
  },
  {//7club
    path: '/clubs',
    name: 'myclubs',
    component: Layout,
    hidden: false,
    meta: {
      title: "7CLUB",
      icon: 'gem-o'
    },
    redirect: "/clubs/clubs",
    children: [
      {
        path: "/clubs/clubs",
        name: 'clubs',
        component: () => import("@/views/clubs/index.vue"),
        meta: {
          title: "7CLUB",
          icon: 'gem-o'
        }
      },
      {
        path: "details",
        name: 'details',
        component: () => import("@/views/clubs/details.vue"),
      },
      {
        path: "/clubs/Topic",
        name: 'Topic',
        component: () => import("@/views/clubs/Topic.vue"),
      },
      {
        path: "/clubs/dishes",
        name: 'dishes',
        component: () => import("@/views/clubs/dishes.vue"),
      },
      {
        path: "/clubs/HotDeta",
        name: 'HotDeta',
        component: () => import("@/views/clubs/HotDeta.vue"),
      },
      {
        path: "/clubs/Participate",
        name: 'Participate',
        component: () => import("@/views/clubs/Participate.vue"),
      },
      {
        path: "/clubs/search",
        name: 'search',
        component: () => import("@/views/clubs/search.vue"),
      }
    ]
  },
  {// 购物车
    path: '/shopCars',
    name: 'myshopCars',
    component: Layout,
    hidden: false,
    meta: {
      title: "购物车",
      icon: 'cart-o'
    },
    redirect: "/shopCars/shopCars",
    children: [
      {
        path: "/shopCars/shopCars",
        name: 'shopCars',
        component: () => import("@/views/shopCars/index.vue"),
        meta: {
          title: "购物车",
          icon: 'cart-o'
        }
      }
    ]
  },
  {// 个人中心
    path: '/personCenters',
    name: 'mypersonCenters',
    component: Layout,
    hidden: false,
    meta: {
      title: "个人中心",
      icon: 'contact-o'
    },
    redirect: "/personCenters/personCenters",
    children: [
      {
        path: "/personCenters/personCenters",
        name: 'personCenters',
        component: () => import("@/views/personCenters/index.vue"),
        meta: {
          title: "个人中心",
          icon: 'contact-o'
        }
      }]
  },
  {//登录
    path: "/login",
    name: "login",
    hidden: true,
    component: () => import("@/views/login/index.vue"),
    meta: {
      title: "登录"
    },
  }
]
const cn = [
  // {//用户评价
  //   path: "/userEvaluates",
  //   name: 'userEvaluates',
  //   component: () => import("@/views/pro/alluserEvaluate.vue"),
  //   meta: {
  //     title: "评价",
  //   }
  // },
  {//商品详情
    path: "/proDetail/:productId",
    component: () => import("@/views/pro/index.vue"),
    meta: {
      title: "商品详情页"
    }
  },
  {//扫一扫
    path: '/qrcodeStream',
    component: () => import("@/views/qrcodeStream/index.vue")
  },
  {//支付
    path: '/topayment',
    component: () => import("@/views/payment/index.vue")
  },
  {//支付成功
    path: '/paysussess',
    component: () => import("@/views/payment/paysussess.vue")
  },
]
const liulu = [
  {
    path: "/Allorder",
    component: () => import("@/views/myorder/allorder.vue"),
    meta: {
      title: "我的订单",
    }
  },
  {
    path: "/Ordersearch",
    name: 'Ordersearch',
    component: () => import("@/views/myorder/ordersearch.vue"),
    meta: {
      title: "订单搜索",
    }
  },
  {
    path: "/Aftersale",
    component: () => import("@/views/myorder/aftersale.vue"),
    meta: {
      title: "售后服务",
    }
  },
  {
    path: "/Customerservice",
    component: () => import("@/views/myservice/customerservice.vue"),
    hidden: true,
    meta: {
      title: "客服中心",
    }
  },
  {
    path: "/Allnotice",
    component: () => import("@/views/myservice/allnotice.vue"),
    hidden: true,
    meta: {
      title: "全部公告",
    }
  },
  {
    path: "/Noticedetails",
    component: () => import("@/views/myservice/noticedetails.vue"),
    hidden: true,
    meta: {
      title: "公告详情",
    }
  },
  {
    path: "/Onlineservice",
    component: () => import("@/views/myservice/onlineservice.vue"),
    hidden: true,
    meta: {
      title: "公告详情",
    }
  },
  {
    path: "/Orderdetails",
    component: () => import("@/views/myorder/orderdetails.vue"),
    hidden: true,
    meta: {
      title: "订单详情",
    }
  },
  {
    path: "/Evaluate",
    component: () => import("@/views/myorder/evaluate.vue"),
    hidden: true,
    meta: {
      title: "去评价",
    }
  }
]
const routes2 = [
  {
    path: "/chat",
    name: 'chat',
    component: () => import("@/views/personCenters/chat.vue"),
    meta: {
      title: "消息",
    }
  }, {
    path: "/coupon",
    name: 'coupon',
    component: () => import("@/views/personCenters/coupon.vue"),
    meta: {
      title: "优惠券",
    }
  },
  {
    path: "/vipcard",
    name: 'vipcard',
    component: () => import("@/views/personCenters/vipcard.vue"),
    meta: {
      title: "七鲜超市卡",
    }
  }, {
    path: "/finance",
    name: 'finance',
    component: () => import("@/views/personCenters/finance.vue"),
    meta: {
      title: "金融福利",
    }
  },
  {
    path: "/personCenters/custom",
    name: 'custom',
    component: () => import("@/views/personCenters/custom.vue"),
    meta: {
      title: "客户服务",
    }
  },
  {
    path: "/personCenters/bill",
    name: 'bill',
    component: () => import("@/views/personCenters/bill.vue"),
    meta: {
      title: "发票中心",
    }
  },
  {
    path: "/personCenters/notices",
    name: 'notices',
    component: () => import("@/views/personCenters/notices.vue"),
    meta: {
      title: "发票须知",
    }
  },
  {
    path: "/personCenters/invheader",
    name: 'invheader',
    component: () => import("@/views/personCenters/invheader.vue"),
    meta: {
      title: "发票抬头",
    }
  },
  {
    path: "/personCenters/salesroom",
    name: 'salesroom',
    component: () => import("@/views/personCenters/salesroom.vue"),
    meta: {
      title: "全部门店",
    }
  },
  {
    path: "/personCenters/procurement",
    name: 'procurement',
    component: () => import("@/views/personCenters/procurement.vue"),
    meta: {
      title: "企业采购",
    }
  },
  {
    path: "/personCenters/investment",
    name: 'investment',
    component: () => import("@/views/personCenters/investment.vue"),
    meta: {
      title: "招商合作",
    }
  },
  {
    path: "/personCenters/Feedback",
    name: 'Feedback',
    component: () => import("@/views/personCenters/Feedback.vue"),
    meta: {
      title: "意见反馈",
    }
  },
  {
    path: "/personCenters/Picking",
    name: 'Picking',
    component: () => import("@/views/personCenters/Picking.vue"),
    meta: {
      title: "领货码",
    }
  },
  {
    path: "/personCenters/survey",
    name: 'survey',
    component: () => import("@/views/personCenters/survey.vue"),
    meta: {
      title: "用户调研",
    }
  },
  {
    path: "/personCenters/licence",
    name: 'licence',
    component: () => import("@/views/personCenters/licence.vue"),
    meta: {
      title: "门店证照",
    }
  },
  {
    path: "/personCenters/AboutUs",
    name: 'AboutUs',
    component: () => import("@/views/personCenters/AboutUs.vue"),
    meta: {
      title: "关于我们",
    }
  },
  {
    path: "/personCenters/privacyPolicy",
    name: 'privacyPolicy',
    component: () => import("@/views/personCenters/privacyPolicy.vue"),
    meta: {
      title: "文件",
    }
  },
  { path: "/adress", component: () => import("../views/Adress/AdressList.vue") },

  { path: "/choose", component: () => import("../views/Adress/ChooseAdress.vue") },

  { path: "/addresspage", component: () => import("../views/Adress/AddressPage.vue") },

  { path: "/people", component: () => import("../views/people/index.vue") },

  { path: "/userInfo", component: () => import("../views/people/user-info.vue") },

  { path: "/qrcode", component: () => import("../views/people/qrcode.vue") },

  { path: "/pass", component: () => import("../views/people/pass.vue") },

  { path: "/payment", component: () => import("../views/people/payment.vue") },

  { path: "/policy", component: () => import("../views/people/policy.vue") },

  { path: "/collection", component: () => import("../views/people/collection.vue") },

  { path: "/other", component: () => import("../views/people/other.vue") },

  { path: "/privacy", component: () => import("../views/people/privacy.vue") },

  { path: "/about", component: () => import("../views/people/about.vue") },



]

const router = new VueRouter({
  routes: [...routes1, ...cn, ...routes2, ...liulu]
})

// let isFresh = true

router.beforeEach((to, from, next) => {
  document.title = to.meta.title
  let token = store.state.user.token
  // if (token || to.path == "/login" || to.path == '/home' || to.path == "/classifys" || to.path == "/clubs" || to.path == "/shopCars" || to.path == "/proDetail/:productId") {
  //   next()
  // } else {
  //   next('/login?redirect=' + to.path)
  // }


  if (token || to.path == "/login") {
    next()
  } else {
    next('/login?redirect=' + to.path)
  }
})


export default router
